/**
 * Copyright (c) 2016-2019 九点科技 All rights reserved.
 *
 * http://www.9dyun.cn
 *
 * 版权所有，侵权必究！
 */
package com.dian.modules.base.controller;

import java.util.Map;
import java.util.List;
import com.dian.common.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import oracle.jdbc.proxy.annotation.Post;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.dian.common.controller.AbstractController;
import com.dian.modules.base.entity.SupplierEntity;
import com.dian.modules.base.service.SupplierService;
import com.dian.modules.base.vo.SupplierExportVO;
import com.dian.common.utils.PageUtils;
import com.dian.common.utils.R;


/**
 * 供应商
 *
 * @author xiaolai
 * @email xiaolai@9dyun.cn
 * @date 2019-06-22 16:07:23
 */
@RestController
@Api("供应商接口")
@RequestMapping("base/supplier")
public class SupplierController extends AbstractController{
    @Autowired
    private SupplierService supplierService;

    /**
     * 供应商列表
     */
    @SysLog("供应商列表")
    @GetMapping("/list")
    @ApiOperation("供应商列表")
    @RequiresPermissions("base:supplier:list")
    public R list(@RequestParam Map<String, Object> params){

        PageUtils page = supplierService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 供应商信息
     */
    @SysLog("供应商信息")
    @ApiOperation("供应商信息")
    @GetMapping("/info/{id}")
    @RequiresPermissions("base:supplier:info")
    public R info(@PathVariable("id") Long id){

        SupplierEntity supplier = supplierService.getInfo(id);

        return R.ok().put(supplier);
    }

    /**
     * 供应商保存
     */
    @SysLog("供应商保存")
    @ApiOperation("供应商保存")
    @PostMapping("/save")
    @RequiresPermissions("base:Supplier:save")
    public R save(@RequestBody SupplierEntity supplier){

		supplierService.saveInfo(supplier);

        return R.ok();
    }

    /**
     * 供应商修改
     */
    @SysLog("供应商修改")
    @ApiOperation("供应商修改")
    @PostMapping("/update")
    @RequiresPermissions("base:supplier:update")
    public R update(@RequestBody SupplierEntity supplier){

		supplierService.updateInfo(supplier);

        return R.ok();
    }

    /**
     * 供应商删除
     */
    @SysLog("供应商删除")
    @ApiOperation("供应商删除")
    @PostMapping("/delete")
    @RequiresPermissions("base:supplier:delete")
    public R delete(@RequestBody Long[] ids){

		supplierService.deleteInfo(ids);

        return R.ok();
    }


    /**
     * 供应商审核
     */
    @SysLog("供应商审核")
    @ApiOperation("供应商审核")
    @GetMapping("/check/{id}")
    @RequiresPermissions("base:supplier:check")
    public R check(@PathVariable("id") Long id){

        supplierService.checkInfo(id);

        return R.ok();
    }


    /**
     * 供应商导出
     */
    @SysLog("供应商导出")
    @ApiOperation("供应商导出")
    @GetMapping("/export")
    @RequiresPermissions("base:supplier:export")
    public void export(@RequestParam Map<String, Object> params){

        List<SupplierExportVO> list = supplierService.exportList(params);

        exportExcel(list,"供应商","供应商",SupplierExportVO.class,"供应商.xls");
    }

}
